﻿<%@ Page Title="" Language="C#" AutoEventWireup="true" Theme="Admin_User_Theme" MasterPageFile="~/Main.Master"
    CodeBehind="ManageUserInfo.aspx.cs" Inherits="WDTAsg2.Admin.ManageUserInfo" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <!-- from http://encosia.com/2009/10/11/do-you-know-about-this-undocumented-google-cdn-feature/ -->
        <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/start/jquery-ui.css"
            type="text/css" rel="Stylesheet" />
        <link href="../Styles/jquery-ui.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
        <script src="../Scripts/jquery.blockUI.js" type="text/javascript"></script>
        
        <script type="text/javascript">
		$(document).ready(function() {
			$("#divEditUser").dialog({
				autoOpen: false,
				modal: true,
				minHeight: 20,
				height: 'auto',
				width: 'auto',
				resizable: false,
				open: function(event, ui) {
					$(this).parent().appendTo("#divEditUserDlgContainer");
				},
			});
		});


		function closeDialog() {
			//Could cause an infinite loop because of "on close handling"
			$("#divEditUser").dialog('close');
		}
		
		function openDialog(title, linkID) {
		
			var pos = $("#" + linkID).position();
			var top = pos.top;
			var left = pos.left + $("#" + linkID).width() + 10;
			
			
			$("#divEditUser").dialog("option", "title", title);
			$("#divEditUser").dialog("option", "position", [left-200, top-200]);
			
			$("#divEditUser").dialog('open');
		}

		function openDialogAndBlock(title, linkID) {
			openDialog(title, linkID);

			//block it to clean out the data
			$("#divEditUser").block({
				message: '<img src=../Images/async.gif" />',
				css: { border: '0px' },
				fadeIn: 0,
				//fadeOut: 0,
				overlayCSS: { backgroundColor: '#ffffff', opacity: 1 } 
			});
		}

		
		function unblockDialog() {
			$("#divEditUser").unblock();
		}

		function onTest() {
			$("#divEditUser").block({
				message: '<h1>Processing</h1>',
				css: { border: '3px solid #a00' },
				overlayCSS: { backgroundColor: '#ffffff', opacity: 1 } 
			});
		}
        </script>
    </head>
    <body>
        <form id="form1">
        <asp:ScriptManager ID="scriptManager" runat="server" />
        <h1>
            Users</h1>
        <div id="divEditUserDlgContainer">
            <div id="divEditUser" style="display: none">
                <asp:UpdatePanel ID="upnlEditUser" runat="server">
                    <ContentTemplate>
                        <asp:PlaceHolder ID="phrEditUser" runat="server">
                            <table cellpadding="3" cellspacing="1">
                                <tr>
                                    <td>
                                        *First Name:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtFirstName" Columns="40" MaxLength="50" runat="server" />
                                        <asp:RequiredFieldValidator ID="vtxtFirstName" runat="server" EnableClientScript="false"
                                            CssClass="ui-state-error-text" Display="Dynamic" ErrorMessage="Required." ControlToValidate="txtFirstName" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        *Last Name:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtLastName" Columns="40" MaxLength="50" runat="server" />
                                        <asp:RequiredFieldValidator ID="vtxtLastName" runat="server" EnableClientScript="false"
                                            CssClass="ui-state-error-text" Display="Dynamic" ErrorMessage="Required." ControlToValidate="txtLastName" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        *Age:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtAge" Columns="20" MaxLength="20" runat="server" />
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" EnableClientScript="false"
                                            CssClass="ui-state-error-text" Display="Dynamic" ErrorMessage="Required." ControlToValidate="txtAge" />
                                        <asp:RangeValidator ID="RangeValidator1" Type="Integer" runat="server" EnableClientScript="false"
                                            CssClass="ui-state-error-text" Display="Dynamic" MinimumValue="18" MaximumValue="90"
                                            ControlToValidate="txtAge" ErrorMessage=" Range"></asp:RangeValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        *Address:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtAddress" Columns="20" MaxLength="20" runat="server" />
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" EnableClientScript="false"
                                            CssClass="ui-state-error-text" Display="Dynamic" ErrorMessage="Required." ControlToValidate="txtAddress" />
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2" align="right">
                                        <asp:Button ID="btnSave" OnClick="btnSave_Click" Text="Save" runat="server" />
                                        <asp:Button ID="btnCancel" OnClick="btnCancel_Click" OnClientClick="closeDialog()"
                                            CausesValidation="false" Text="Cancel" runat="server" />
                                    </td>
                                </tr>
                            </table>
                        </asp:PlaceHolder>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
        </div>
        <!-- divEditUserDlgContainer -->
        <asp:UpdatePanel ID="upnlUsers" UpdateMode="Conditional" runat="server">
            <ContentTemplate>
                <asp:GridView ID="gvUsers" CssClass="tblUsers" runat="server" GridLines="None" AutoGenerateColumns="False"
                    CellPadding="4" CellSpacing="1" OnRowDataBound="gvUser_RowDataBound" OnRowCommand="gvUsers_RowCommand">
                    <Columns>
                        <asp:TemplateField HeaderText="Name">
                            <ItemTemplate>
                                <%# Eval("FirstName") + " " + Eval("LastName")%>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="Email" HeaderText="Email" />
                        <asp:BoundField DataField="Age" HeaderText="Age" />
                        <asp:BoundField DataField="Address" HeaderText="Address" />
                        <asp:TemplateField HeaderText="Actions">
                            <ItemTemplate>
                                <asp:LinkButton ID="btnEdit" Text="Edit" CommandName="EditUser" CausesValidation="false"
                                    CommandArgument='<%#Eval("Email")%>' runat="server"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <asp:Button ID="btnRefreshGrid" CausesValidation="false" OnClick="btnRefreshGrid_Click"
                    Style="display: none" runat="server"></asp:Button>
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:UpdatePanel ID="upnlJsRunner" UpdateMode="Always" runat="server">
            <ContentTemplate>
                <asp:PlaceHolder ID="phrJsRunner" runat="server"></asp:PlaceHolder>
            </ContentTemplate>
        </asp:UpdatePanel>
        </form>
    </body>
    </html>
</asp:Content>
